package com.yq.ylmall.search.consumer;

import com.yq.ylmall.constant.ProductConstant;
import com.yq.ylmall.search.service.IProductService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class ProductConsumer {

    private final IProductService productService;

    /**
     * 监听商品上架，搜索引擎商品上架
     *
     * @param id 商品ID
     */
    @RabbitListener(queues = ProductConstant.PRODUCT_UPPER_QUEUE)
    public void UpperConsumer(String id) {
        log.info("监听商品上架 -> 商品ID：{}", id);
        productService.upperProduct(Long.parseLong(id));
    }

    /**
     * 监听商品下架，搜索引擎商品下架
     *
     * @param id 商品ID
     */
    @RabbitListener(queues = ProductConstant.PRODUCT_LOWER_QUEUE)
    public void lowerConsumer(String id) {
        log.info("监听商品下架 -> 商品ID：{}", id);
        productService.lowerProduct(Long.parseLong(id));
    }

}
